package service

import (
	log "github.com/sirupsen/logrus"
	"runtime"
	"usbipproxy/common/platform"
	"usbipproxy/domain/vo"
)

/*
C:\Windows\System32>usbip port
Imported USB devices
====================
Port 31: device in use at Super Speed(5000Mbps)

	unknown vendor : unknown product (3535:6300)
	  -> usbip://192.168.137.188:3240/3-1
	  -> remote bus/dev 003/001

C:\Windows\System32>usbip detach -p 31
port 31 is succesfully detached
*/
type UsbIpClientCmdService interface {
	PortList() []*vo.UsbInfo
	//DetachPort(port int) error
	DetachByBusId(busId, vendorId string) error
	//MMDeviceUtil.exe -e attach_by_parent -s 1 -P "SWD\USBIP2\1959891959589896192"
	AttachByParent(connId int64) (bool, error)
	//MMDeviceUtil.exe -e detach_by_parent -s 1 -P "SWD\USBIP2\1959891959589896192"
	DetachByParent(connId int64) (bool, error)
	//Get-AudioDevice -List
	GetAudioDeviceList() ([]vo.AudioDevice, error)
	//config default audio device
	SetDefaultAudioDevice(index int, deviceType string, isCommunication bool) error
}

var FactoryUsbIpClientCmd = &UsbIpClientCmdServiceFactory{}

type UsbIpClientCmdServiceFactory struct{}

func (f *UsbIpClientCmdServiceFactory) Create() UsbIpClientCmdService {
	os := runtime.GOOS
	switch os {
	case "windows":
		log.Infof("当前是 Windows 系统")
		return NewUsbIpClientWindowsCmdServiceImpl(platform.GetPlatformHandler())
	case "linux":
		log.Infof("当前是 Linux 系统")
		return NewUsbIpClientWindowsCmdServiceImpl(platform.GetPlatformHandler())
	default:
		log.Infof("当前是其他系统：%s\n", os)
	}
	return nil
}
